package com.black.platform.menu.web;

import com.black.common.auth.UserContextHolder;
import com.black.common.vo.MenuVo;
import com.black.common.web.ApiResponse;
import com.black.common.web.ApiResponseBuilder;
import com.black.platform.menu.service.handler.MenuHandlerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"系统菜单-API"})
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MenuController {

    private final MenuHandlerService menuHandlerService;

    @GetMapping("system/{systemCode}/menus")
    @ApiOperation(value = "根据系统代码获取用户拥有的菜单")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "systemCode", paramType = "path", value = "系统代码"),
    })
    public ApiResponse<List<MenuVo>> getSystemMenus(@PathVariable("systemCode") String systemCode) {
        return ApiResponseBuilder.ok(menuHandlerService.getMenuByRequestUserId(UserContextHolder.getUserId(), systemCode));
    }

    @GetMapping("menus/search/{systemCode}")
    @ApiOperation(value = "根据系统代码获取该系统的所有菜单")
    @ApiImplicitParam(name = "systemCode", paramType = "path", value = "系统代码")
    public ApiResponse<List<MenuVo>> search(@PathVariable("systemCode") String systemCode) {
        return ApiResponseBuilder.ok(menuHandlerService.search(systemCode));
    }

}
